package service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.ConfigureDao;
import entity.Configure;
import service.ConfigureService;

@Service
public class ConfigureServiceImpl implements ConfigureService{

	//注解的方式注入SqlSessionFactory
	@Autowired
	SqlSessionFactory factory;

	
	//获取全部的配置信息
	@Override
	public List<Configure> find() {
		SqlSession sqlSession = null;
		List<Configure> list = null;  
		try {
			sqlSession = factory.openSession();
			ConfigureDao dao = sqlSession.getMapper(ConfigureDao.class); //使用动态代理获取对象
			list = dao.find();   
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
			sqlSession.close();
		}
		return list;
	}

	@Override
	public Configure findSingle(String name) {
		SqlSession sqlSession = null;
		try {
			sqlSession = factory.openSession();
			ConfigureDao dao = sqlSession.getMapper(ConfigureDao.class); //使用动态代理获取对象
			Configure configure = dao.findSingle(name); 
			System.out.println(configure.toString());
			return configure;
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
			sqlSession.close();
		}
		return null;
	}

}
